#include "mySort.h"
#include <iostream>
#include <string>
#include <cmath>

MySort::MySort(){
	num = 0;
	origin = NULL;
}

MySort::MySort(int num, int* origin){
	this->num = num;
	this->origin = new int[num];
	for (int i = 0; i < num; i++)
	{
		this->origin[i] = origin[i];
	}
}

MySort::~MySort(){
	;
}

void MySort::changeSwap(int& a, int& b){
	;
}

string MySort::printNum(){
	for (int i = 0; i < num-1; i++)
	{
		cout << origin[i] << " ";
	}
	cout << origin[num - 1] << endl;
	return "\0";
}

string MySort::paritySort(){
	int ifJi = 0;
	if (num % 2) ifJi = 1;
	int opr = 1;
	int joo = 1;
	while (opr)
	{
		int tmz = 0;
		if (joo)
		{
			joo = 0;
			int tem;
			if (!ifJi)tem = num - 1;
			else tem = num;
			for (int i = 1; i <tem ; i += 2)
			{
				if (origin[i] > origin[i + 1])
				{
					swap(origin[i], origin[i + 1]);
					printNum();
					tmz++;
				}
			}
			
		}
		else
		{
			joo = 1;
			int tem;
			if (ifJi) tem = num - 1;
			else tem = num;
			for (int i = 0; i < tem; i += 2)
			{
				if (origin[i] > origin[i + 1])
				{
					swap(origin[i], origin[i + 1]);
					printNum();
					tmz++;
					
				}
			}
		}
		if (!tmz)  opr = 0;
	}



	return "\0";
}

string MySort::bubbleSort(){
	int opr = 1;
	int pan = 1;
	while (opr)
	{
		if (pan)
		{
			pan = 0;
			int tmz = 0;
			for (int i = 0; i < num - 1; i++)
			{

				if (origin[i] > origin[i + 1])
				{
					swap(origin[i], origin[i + 1]);
					printNum();
					tmz++;
				}
			}
			if (tmz == 0)
				opr = 0;
		}
		else
		{
			pan = 1;
			int tmz = 0;
			for (int i = num - 1; i > 1; i--)
			{
				if (origin[i] < origin[i - 1])
				{
					swap(origin[i], origin[i - 1]);
					printNum();
					tmz++;
				}
			}
			if (tmz == 0)
				opr = 0;
		}
	}
	return "\0";
}
